home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pdcurs21.zip / PRIVATE.ZIP / _MAKENEW.C < prev    next >
Text File  |  1992-11-21  |  4KB  |  144 lines

  1. #ifndef NO_MEMORY_H
  2. #include <memory.h>
  3. #endif
  4. #define        CURSES_LIBRARY  1
  5. #include <curses.h>
  6.  
  7. #ifndef        NDEBUG
  8. char *rcsid__makenew = "$Header: c:/curses/private/RCS/_makenew.c%v 2.0 1992/11/15 03:24:28 MH Rel $";
  9. #endif
  10.  
  11.  
  12.  
  13.  
  14. /*man-start*********************************************************************
  15.  
  16.   PDC_makenew()        - Create a WINDOW* (sans line allocation)
  17.  
  18.   PDCurses Description:
  19.        This is a private PDCurses routine.
  20.  
  21.        Allocates all data for a new WINDOW* except the actual lines
  22.        themselves.
  23.  
  24.   PDCurses Return Value:
  25.        This function returns a valid WINDOW* on success and NULL on error.
  26.  
  27.   PDCurses Errors:
  28.        If PDC_makenew() is unable to allocate memory for the window
  29.        structure, it will free all allocated memory and return
  30.        a NULL pointer.
  31.  
  32.   Portability:
  33.        PDCurses        WINDOW* makenew( int num_lines, int num_columns,
  34.                                         int begy, int begx );
  35.  
  36. **man-end**********************************************************************/
  37.  
  38. WINDOW*        PDC_makenew(int num_lines, int num_columns, int begy, int begx)
  39. {
  40. extern void*   (*mallc)( size_t );
  41. extern void*   (*callc)( size_t, size_t );
  42. extern void    (*fre)( void* );
  43.  
  44.        short   i;
  45.        WINDOW *win;
  46.  
  47.        /*
  48.        *       Use the standard runtime malloc/calloc package or use
  49.        *       the user's emalloc/ecalloc package.
  50.        *
  51.        *       Allocate the window structure itself
  52.        */
  53.        if ((win = (*mallc)(sizeof(WINDOW))) == (WINDOW *)NULL)
  54.        {
  55.                return( win );
  56.        }
  57.  
  58.        /*
  59.        * allocate the line pointer array
  60.        */
  61.        if ((win->_y = (*callc)(num_lines, sizeof(chtype *))) == NULL)
  62.        {
  63.                (*fre)(win);
  64.                return( (WINDOW *)NULL );
  65.        }
  66.  
  67.        /*
  68.        * allocate the minchng and maxchng arrays
  69.        */
  70.        if ((win->_firstch = (*callc)(num_lines, sizeof(int))) == NULL)
  71.        {
  72.                (*fre)(win->_y);
  73.                (*fre)(win);
  74.                return( (WINDOW *)NULL );
  75.        }
  76.        if ((win->_lastch = (*callc)(num_lines, sizeof(int))) == NULL)
  77.        {
  78.                (*fre)(win->_firstch);
  79.                (*fre)(win->_y);
  80.                (*fre)(win);
  81.                return( (WINDOW *)NULL );
  82.        }
  83.  
  84.        /*
  85.        * initialize window variables
  86.        */
  87.        win->_curx = 0;
  88.        win->_cury = 0;
  89.        win->_maxy = num_lines;         /* real max screen size */
  90.        win->_maxx = num_columns;       /* real max screen size */
  91.        win->_pmaxy = num_lines;        /* real max window size */
  92.        win->_pmaxx = num_columns;      /* real max window size */
  93.        win->_begy = begy;
  94.        win->_begx = begx;
  95.        win->_flags = 0;
  96.        win->_attrs = 0;                /* No attributes */
  97.        win->_tabsize = 8;
  98.        win->_clear = (bool) ((num_lines == LINES) && (num_columns == COLS));
  99.        win->_leave = FALSE;
  100.        win->_scroll = FALSE;
  101.        win->_nodelay = FALSE;
  102.        win->_use_keypad = FALSE;
  103.        win->_use_idl = FALSE;
  104.        win->_tmarg = 0;
  105.        win->_bmarg = num_lines - 1;
  106.        win->_title = NULL;
  107.        win->_title_ofs = 1;
  108.        win->_title_attr = win->_attrs;
  109.        win->_blank = ' ';
  110.        win->_parent = NULL;
  111.  
  112.        memset(win->_borderchars, '\0', 8*sizeof(chtype));
  113.  
  114.        /*
  115.        * init to say window unchanged
  116.        */
  117.        for (i = 0; i < num_lines; i++)
  118.        {
  119.                win->_firstch[i] = 0;
  120.                win->_lastch[i] = num_columns - 1;
  121.        }
  122.  
  123.        /*
  124.        * set flags for window properties
  125.        */
  126.        if ((begy + num_lines) == LINES)
  127.        {
  128.                win->_flags |= _ENDLINE;
  129.                if ((begx == 0) &&
  130.                    (num_columns == COLS) &&
  131.                    (begy == 0))
  132.                {
  133.                        win->_flags |= _FULLWIN;
  134.                }
  135.        }
  136.  
  137.        if (((begy + num_lines) == LINES) &&
  138.            ((begx + num_columns) == COLS))
  139.        {
  140.                win->_flags |= _SCROLLWIN;
  141.        }
  142.        return( win );
  143. }
  144.